﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" 
Inherits="System.Web.Mvc.ViewPage<FarmerStore.ViewModels.ShoppingCartViewModel>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    购物车
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

    <script src="/Scripts/MicrosoftAjax.js" type="text/javascript"></script>
    <script src="/Scripts/MicrosoftMvcAjax.js" type="text/javascript"></script>
    <script src="/Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>

    <script type="text/javascript">
        function handleUpdate(context) {
            // Load and deserialize the returned JSON data
            var json = context.get_data();
            var data = Sys.Serialization.JavaScriptSerializer.deserialize(json);

            // Update the page elements
            $('#row-' + data.DeleteId).fadeOut('slow');
            $('#cart-status').text('Cart (' + data.CartCount + ')');
            $('#update-message').text(data.Message);
            $('#cart-total').text(data.CartTotal);
        }
    </script>
    <div id="submain">
        <h3>
            <em>查看</em> 你的购物车:
        </h3>
        <p class="button">
            <%: Html.ActionLink("结账 >>", "AddressAndPayment", "Checkout")%>
        </p>

        <div id="update-message"></div>

        <table id="productsincart">

            <tr>
                <th>产品名称</th>
                <th>单价</th>
                <th>数量</th>
                <th></th>
            </tr>

            <% foreach (var item in Model.CartItems) { %>
            <tr id="row-<%: item.RecordId %>">
                <td>
                    <%: Html.ActionLink(item.Product.Title, "Details", "Store", 
                        new { id = item.Id }, null)%>
                </td>
                <td>
                    <%: item.Product.Price %>
                </td>
                <td>
                    <%: item.Count %>
                </td>
                <td>
                    <%: Ajax.ActionLink("从购物车中移除", "RemoveFromCart", 
                        new { id = item.RecordId }, 
                        new AjaxOptions { OnSuccess = "handleUpdate" })%>
                </td>
            </tr>
            <% } %>

            <tr>
                <td>总金额</td>
                <td></td>
                <td></td>
                <td id="cart-total">
                    <%: Model.CartTotal %>
                </td>
            </tr>

        </table>
    </div>

</asp:Content>